home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / DESK / CORE / Desk / h_doc / BackTrace next >
Text File  |  1996-08-19  |  3KB  |  127 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for 
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #                                      
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    DeskMem.h
  12.     Author:  Copyright © 1995 Tom Hughs, Paul Field, Julian Smith
  13.     Version: 1.00 (17 Apr 1996)
  14.     Purpose: Functions which walk the current stack.
  15. */
  16.  
  17.  
  18. /*
  19. NB, A warning to people using CMHG IRQ veneers - I have discovered to my
  20. cost that Desk_BackTrace functions fail to walk the stack provided by
  21. these veneers, and so give an address exception... I suspect that the fp
  22. pointer isn't NULL when it should be, or something.
  23.  */
  24.  
  25.  
  26. #ifndef __Desk_BackTrace_h
  27. #define __Desk_BackTrace_h
  28.  
  29.  
  30. #include <stdio.h>
  31.  
  32. #include "kernel.h"
  33.  
  34.  
  35. #ifdef __cplusplus
  36.     extern "C"    {
  37. #endif
  38.  
  39.  
  40. void    Desk_BackTrace_SupportCurrentFrame( _kernel_unwindblock *frame);
  41. /*
  42. Read the current values of fp, sl and pc (so that _kernel_unwind() can
  43. be called).
  44.  */
  45.  
  46. void    Desk_BackTrace_OutputToStdErr( void);
  47. /*
  48. Generates a stack backtrace on stderr.
  49.  */
  50.  
  51.  
  52. void    Desk_BackTrace_OutputToStreamWithPrefix( FILE* stream, const char* prefix);
  53. /*
  54. Sends a backtrace to 'stream', prefixing each line with 'prefix'.
  55.  */
  56.  
  57.  
  58. typedef int (*Desk_backtrace_printf_fn)( void* reference, const char* format, ...);
  59.  
  60. void    Desk_BackTrace_OutputToFFunctionWithPrefix( Desk_backtrace_printf_fn fn, void* reference, const char* prefix);
  61. /*
  62. Sends a backtrace to 'fn', prefixing each line with 'prefix'.
  63.  */
  64.  
  65.  
  66. extern unsigned int    Desk_BackTrace_GetPC( void);
  67. /*
  68. Returns PC for caller.
  69.  */
  70.  
  71. extern unsigned int    Desk_BackTrace_GetSL( void);
  72. /*
  73. Returns value of stack-limit register.
  74.  */
  75.  
  76.  
  77. #define    Desk_BackTrace_GetPC2() ((void*) ( Desk_BackTrace_GetPC() & (0x3fffffc)))
  78. /*
  79. Strips off status flags and processor mode from the current PC.
  80.  */
  81.  
  82.  
  83. int    Desk_BackTrace_GetNestingDepth( void);
  84. /*
  85. Returns the current function-nesting depth. Only functions which set up
  86. a stack-frame are detected, and note that Shared C Lib stack-extension
  87. functions create a stack-frame.
  88.  */
  89.  
  90.  
  91. typedef struct    {
  92.     int        n;
  93.     unsigned int**    functions;
  94.     }
  95.     Desk_BackTrace_functionlist;
  96.  
  97. #define    Desk_BackTrace_MAXFNS 256
  98.  
  99.  
  100. const Desk_BackTrace_functionlist*    Desk_BackTrace_GetCurrentFunctions( void);
  101. /*
  102. Returns a pointer to an internal object containing array of current
  103. functions. Each entry in the array is the address of the save
  104. instruction used to create each stack-frame. This instruction is usually
  105. a 'STM ...'.
  106. 'functions[0]' is address of most recent save instruction. 'n' is number
  107. of functions found.
  108.  
  109. A maximum of Desk_BackTrace_MAXFNS are found.
  110.  */
  111.  
  112.  
  113.  
  114. const char*    Desk_BackTrace_GetFunctionName( const void* ptr);
  115. /*
  116. Returns function name if ptr is <= 4 words after start of function and
  117. the name is embedded in code.
  118. Otherwise returns NULL.
  119.  */
  120.  
  121.  
  122. #ifdef __cplusplus
  123. }
  124. #endif
  125.  
  126. #endif
  127.